package com.chen.module.testproducerconsumer;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.MessageQueue;
import android.view.View;

import com.chen.module.testproducerconsumer.jdasynctool.executor.Async;
import com.chen.module.testproducerconsumer.jdasynctool.executor.timer.SystemClock;
import com.chen.module.testproducerconsumer.jdasynctool.wrapper.WorkerWrapper;
import com.chen.module.testproducerconsumer.test.ParWorker1;
import com.chen.module.testproducerconsumer.test.ParWorker2;
import com.chen.module.testproducerconsumer.test.ParWorker3;

import java.util.Random;
import java.util.concurrent.ExecutionException;

public class MainActivity extends AppCompatActivity {

    private CenterControl centerControl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        centerControl = CenterControl.getInstance();
        CustomMessageQueue messageQueue = new CustomMessageQueue();
        new ProducerThread(messageQueue , 1).start();
        new ConsumerThread(messageQueue , 1).start();
        new ProducerThread(messageQueue , 2).start();
        new ConsumerThread(messageQueue , 2).start();
        findViewById(R.id.tv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                centerControl.weekUpThread();
            }
        });
        findViewById(R.id.tv2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                centerControl.putMsg2(new MessageBean(new Random().nextInt(5)));
//                centerControl.weekUpThread2();
            }
        });
        findViewById(R.id.tv_worker).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              /*  try {
//                    testWork1();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }*/
            }
        });
        centerControl.putMsg(new MessageBean(1));
        centerControl.putMsg(new MessageBean(2));
        centerControl.putMsg(new MessageBean(3));
        centerControl.putMsg(new MessageBean(4));
        centerControl.putMsg(new MessageBean(5));

       /* centerControl.putMsg2(new MessageBean(21));
        centerControl.putMsg2(new MessageBean(22));
        centerControl.putMsg2(new MessageBean(23));
        centerControl.putMsg2(new MessageBean(24));
        centerControl.putMsg2(new MessageBean(25));*/
    }

}
